<template>
  <div>
      父组件
      <br>
    父组件传递值：
    <br>
    <input type="text" v-model="name">
    <br>
    <son-com :data='name' @childValue='value'/>
    <br>
     父组件接收子组件的值 {{childData}}
     <br>
     接口数据传值
      <ul>
          <li v-for="(item,keys) in dataList" :key='keys'>{{item.texts}}</li>
          <li>{{dataList}}</li>
          <li></li>
          <li></li>
      </ul>

      <br>
      非父子传值
       bus传递的值 <button @click="busDown">点击</button>
       {{busData}}
  </div>

     
</template>

<script>
 import sonCom from './sonCom'
 import axios from 'axios';
export default {
    name:'faCom',
    components:{
        sonCom
    },
    data(){
        return{
            name:'',
            childData:'',
             dataList:{},
            httpUrl:'https://api.apiopen.top/getJoke?page=1&count=2&type=video',
            busData:'你快乐吗',
        }
    },


    mounted(){
      const url = this.$data.httpUrl
      this.getData(url)
      this.bus.$on('busValue',msg=>{
        console.log(msg);
        this.busData = msg;
      })
    },


    methods:{
        value(e){
            console.log(e);
            this.$data.childData = e
        },
     getData: function(url){
     axios.get(url)
     .then(res=>{
       console.log(res);
       this.$data.dataList = res.data.result;
       

     })
     .catch(err=>{
       console.log(err);
     })
   },
    busDown(){
        this.bus.$emit('busValue',this.busData)
    }
    }
   


}
</script>

<style>

</style>